<?php
/**
 * Created by PhpStorm.
 * User: liuyiwei@7659.com
 * Date: 2018/9/4
 * Time: 9:55
 */

namespace backend\helpers;

use common\components\RabbitMQ;
use PhpAmqpLib\Message\AMQPMessage;

class MqHelper
{
    public static function qiniuSaveAs($data) {
        // 发消息
        try {
            $connection = RabbitMQ::getConnection();

            $channel = $connection->channel();
            $channel->queue_declare('qiniu_pili_saveas', false, true, false, false, true);
            $msg = new AMQPMessage(json_encode($data),
                array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
            );
            $channel->basic_publish($msg, '', 'qiniu_pili_saveas');

        } catch (\Exception $exception) {
            return ['code'=>0, 'msg'=>$exception->getMessage()];
        }

        return ['code'=>1];
    }
}